using System.Collections.Generic;

using TrueCode.DependencyManager.BuildActions.BuidBit;

namespace TrueCode.DependencyManager.BuildActions.BuildBit
{
  public class BuildBit : IBuildBit
  {
    private readonly Dictionary< SessionAim, object > _instances = new Dictionary< SessionAim, object >();

    public void Execute( IBuildSession context )
    {
      object instance;

      var sessionAim = context.SessionAim;
      if( _instances.TryGetValue( context.SessionAim, out instance ) )
        context.Instance = instance;
      else
      {
        context.ExecuteNextBuildAction();
        if( context.Instance != null )
          _instances.Add( sessionAim, context.Instance );
      }
    }
  }
}